
<body class="iframe">
    <div class="userlist">
        <div class="frame-header">
            <h2><i class="layui-icon">&#xe705;</i>联系人管理</h2>
        </div>
        <h4 class="layui-bg-dark frame-title"><i class="layui-icon">&#xe65f;</i>发件人列表</h4>
        <div class="toolbox layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline" style="width: 80px;">
                        <input type="checkbox" title="全选" lay-skin="primary" lay-filter="checkall">
                    </div>
                    <div class="layui-input-inline" style="width: 100px;">
                        <button class="layui-btn layui-btn-danger delall"><i class="layui-icon">&#xe640;</i>删除</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="data-table">
            <table class="layui-table">
                <thead>
                    <tr>
                        <th></th>
                        <th>id</th>
                        <th>发件邮箱</th>
                        <th>授权账号</th>
                        <th>授权密码</th>
                        <th>今日发送量</th>
                        <th>累计发送量</th>
                        <th>今日可用</th>
                        <th>添加时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>
        <div id="template-page" class="page"></div>
    </div>
</body>
<script>
    var startpage = 0, len = 10;

    layui.use(['form', 'laypage', 'layer'], function () {
        var form = layui.form, laypage = layui.laypage, layer = layui.layer;

        getAddressList(startpage, len);

        laypage.render({
            elem: 'template-page'
            , count: "<?= $sumRecords ?>" //数据总数，从服务端得到
            , theme: '#01AAED'
            , limit: len
            , curr: 1
            , jump: function (obj, first) {
                page = obj.curr - 1;
                len = obj.limit;
                if (!first) {
                    //do something
                    startpage = page;
                    getAddressList(startpage, len);
                }
            }
        });




        //全选特效
        form.on('checkbox(checkall)', function (data) {
            let checkstate = data.elem.checked;//全选状态
            $("td input[type=checkbox]").prop('checked', checkstate);
        });
        $(document).on('click', 'td input[type=checkbox]', function () {
            let len = $("td input[type=checkbox]").length;
            let clen = 0;
            $("td input[type=checkbox]:checked").each(function () {
                clen++;
            });
            let state = len == clen ? true : false;
            if (state) {
                $(".checkall").prop('checked', true);
                $(".layui-unselect").addClass("layui-form-checked");
            } else {
                $(".checkall").prop('checked', false);
                $(".layui-unselect").removeClass("layui-form-checked");
            }
        })
        //全选删除  
        $(".delall").on('click', function () {
            let url = '<?= site_url('address/del_address') ?>';
            let ids = getCheckedItems();
            let jsonData = {
                'type': 1,
                'ids': checkedArr
            };
            ids.length == 0 ? layer.msg('请选择需要删除项!') : paramsRequest(url, jsonData, layer, getAddressList, startpage, len);
            ;
        })
        //删除单条记录
        $(document).on('click', '.del', function () {
            let url = '<?= site_url('address/del_address') ?>';
            let ids = getId($(this));
            let jsonData = {
                'type': 1,
                'ids': ids
            };
            paramsRequest(url, jsonData, layer, getAddressList, startpage, len);
        });

        $(document).on('click', '.active', function () {
            let url = '<?= site_url('address/update_address') ?>';
            let ids = getId($(this));
            let enable = $(this).attr('active');
            let jsonData = {
                'type': 1,
                'ids': ids,
                'enable': enable
            };
            paramsRequest(url, jsonData, layer, getAddressList, page, len);
        });



    });


    function getAddressList(page, limit) {
        let url = "<?= site_url('address/get_address_list') ?>";
        let jsonData = {
            'type': 1,
            'page': page,
            'limit': limit
        };
        $.get(url, jsonData, function (redata) {
            let str = '';
            if (redata.errno == '666') {
                for (x in redata.addresslist) {
                    let num = parseInt(x) + 1 + page * len;
                    let enable = redata.addresslist[x].enable;
                    let enablestr = '';
                    let activestr = '';
                    if (enable == '1') {
                        enablestr = '<span class="layui-badge">可用</span>';
                        activestr = '<button class="layui-btn layui-btn-warm layui-btn-xs active" active="0"><i class="layui-icon">&#x1007;</i>今日禁用</button>';
                    } else {
                        enablestr = '<span class="layui-badge layui-bg-gray">过期</span>';
                        activestr = '<button class="layui-btn layui-btn-xs layui-btn-normal active" active="1"><i class="layui-icon">&#xe605;</i>重新启用</button>';
                    }
                    str += '<tr tid=' + redata.addresslist[x].id + '><td><input type="checkbox" /></td><td>' + num + '</td><td>' + redata.addresslist[x].email + '</td><td>' + redata.addresslist[x].approve_username + '</td><td>' + redata.addresslist[x].approve_password + '</td><td>' + redata.addresslist[x].today_usage + '</td><td>' + redata.addresslist[x].total_usage + '</td><td>' + enablestr + '</td><td>' + redata.addresslist[x].create_time + '</td><td><div class="layui-btn-group">' + activestr + '<button class="layui-btn layui-btn-danger layui-btn-xs del"><i class="layui-icon">&#xe640;</i>删除</button></div></td></tr>';
                }
                $(".data-table tbody").html(str);
            } else {
                layer.msg(redata.error);
                $(".data-table tbody").html(str);
            }
        }, 'json');
    }
</script>

</html>